import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: tgy
 * @Date: 2020-09-04 10:35
 */
public class ThreadPoolException {

    public static void main(String[] args) {



        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("stats-pool-%d").setUncaughtExceptionHandler((thread,throwable)->{

            System.out.println(thread + " xx " + throwable);
        }).build();
        int processors = Runtime.getRuntime().availableProcessors();

        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(processors,
                    processors, 0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(100),namedThreadFactory);


        for (int i = 0; i < 100; i++) {

            final int j = i;
            poolExecutor.execute(()->{


//                System.out.println("info-" + j);

                System.out.println(Thread.currentThread().getName());

                if (j % 10 == 7) {

                    throw new RuntimeException("info-" + j);
                }

            });
        }


        poolExecutor.shutdown();

    }
}
